#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

struct data { int u, v, c; };

int const maxn = 2002;
bool map[maxn][maxn];
bool vis[maxn];
vector<data> da;
int n, m;

void dfs(int x)
{
	vis[x] = true;
	for (int i = 0; i < n; i++)
		if (map[x][i] && !vis[i]) dfs(i);
}

bool judge(int x)
{
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) map[i][j] = false;
	for (int i = 0; i < m; i++) {
		if (da[i].c <= x)
			map[da[i].u][da[i].v] = map[da[i].v][da[i].u] = true;
	}
	fill(vis, vis+n, false);
	dfs(0);
	for (int i = 0; i < n; i++) if (!vis[i]) return false;
	return true;
}

int main()
{
	scanf("%d%d", &n, &m);
	da.resize(m);
	int min_c = 1<<30, max_c = 0;
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &da[i].u, &da[i].v, &da[i].c);
		da[i].u--; da[i].v--;
		min_c = min(min_c, da[i].c);
		max_c = max(max_c, da[i].c);
	}
	int l = min_c, r = max_c;
	while (l+1 < r) {
		int mid = (l+r)/2;
		if (judge(mid)) r = mid;
		else            l = mid + 1;
	}
	if (judge(l)) r = l;
	printf("%d\n", r);
}



